fix(api): allow setting default project when none is currently set#976
Merged
Conversation
The v2 set_default_project_by_id handler fetched the current default solely to echo it as old_project in the response, and raised 404 "No default project is currently set" when none existed. That guard (marked # pragma: no cover, never tested) made the bootstrap/recovery case impossible: with no default row in the DB, `bm project default <name>` always failed -- yet that is exactly the command you reach for when no default is set. ProjectStatusResponse.old_project is already Optional, so the guard served no schema requirement. Remove it and build old_project only when a previous default exists, else pass None. Add a regression test that clears is_default, sets a default via the endpoint, and asserts 200, old_project is None, the new project is default, and a follow-up read-back returns it. Closes #975 Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Drew Cain <groksrc@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #975
Problem
bm project default <name>failed withNo default project is currently set— but setting the default is exactly the command you reach for when none is set, making a recoverable state unrecoverable from the CLI (the bootstrap/recovery case).Repro (before the fix)
Root cause
src/basic_memory/api/v2/routers/project_router.pyset_default_project_by_idfetched the current default solely to echo it asold_projectin the response, and raised404when there was none. That guard was marked# pragma: no cover— the no-current-default path was never tested.ProjectStatusResponse.old_projectis alreadyOptional, so the 404 served no schema requirement.Fix
Remove the 404 guard. Build
old_project=ProjectItem(...)only when a previous default exists, otherwise passold_project=None. The rest of the handler is unchanged. No schema change needed.A check of the rest of
src/basic_memory/api/confirmed there is no v1 router (onlyv2/) and the"No default project is currently set"string now appears nowhere in the tree, so there was no duplicate pattern to fix.Test coverage
Added
test_set_default_project_when_none_is_set: clearsis_defaultso no row is default, calls the set-default endpoint, and asserts200,old_project is None, the new project is default, and a follow-upget_default_project()returns it. All existing tests stay green. The removed# pragma: no coverguard is gone, and both branches of the newold_projectconstruction are exercised by the existing and new tests.Verification
uv run pytest tests/api/v2/test_project_router.py tests/services/test_project_service.py tests/repository/test_project_repository.py tests/cli/test_project_list_and_ls.py— 91 passed, 2 skippeduv run ruff check+ruff format --checkon changed files — cleanuv run ty check src tests test-int— All checks passedEnd-to-end (the user's actual repro)
bm project default qanow succeeds where it previously failed withNo default project is currently set. No #974-shaped config/DB drift was encountered on this path.🤖 Generated with Claude Code